var cut[Nstate,Ncat-1];

model {
  for (i in 1:N){
    y[i] ~ dnorm(mu[i], 1)
    mu[i] <- b.state[stateID[i]] + b.1*chgUnemp1211[i] + b.2*avgUnemp12[i] + b.3*chgInc1211[i]+ b.4*inc12[i] + b.5*younger30[i]+  b.6*older65[i] + b.7*female[i] + b.8*black[i] + b.9*latino[i] + b.10*noHighSchool[i] + b.11*HighSchool[i] + b.12*someCollege[i] + b.13*fourCollege[i] + b.14*income[i] + b.15*unemployed[i] + b.16*fullTime[i] + b.17*partTime[i] + b.18*ownHome[i] + b.19*newsInt[i] + b.20*ideol[i] + b.21*Dem[i] + b.22*Rep[i] + b.23*Ind[i]
    for (k in 1:(Ncat-1)) { logit(Q[i,k]) <- cut[stateID[i], k] - mu[i]}
    p[i, 1] <- Q[i,1]
    for (k in 2:(Ncat-1)){ p[i,k] <- Q[i,k] - Q[i, (k-1)]}
    p[i, Ncat] <- 1 - Q[i, (Ncat-1)]
  }
  for (j in 1:Nstate){
    b.state[j] ~ dnorm(mu.state, tau.state)
  }
  mu.state ~ dnorm(0, 0.0001)
  tau.state <- pow(sigma.state, -2)
  sigma.state ~ dunif(0, 1000)
  b.1 ~ dnorm(0, 0.0001)
  b.2 ~ dnorm(0, 0.0001)
  b.3 ~ dnorm(0, 0.0001)
  b.4 ~ dnorm(0, 0.0001)
  b.5 ~ dnorm(0, 0.0001)
  b.6 ~ dnorm(0, 0.0001)
  b.7 ~ dnorm(0, 0.0001)
  b.8 ~ dnorm(0, 0.0001)
  b.9 ~ dnorm(0, 0.0001)
  b.10 ~ dnorm(0, 0.0001)
  b.11 ~ dnorm(0, 0.0001)
  b.12 ~ dnorm(0, 0.0001)
  b.13 ~ dnorm(0, 0.0001)
  b.14 ~ dnorm(0, 0.0001)
  b.15 ~ dnorm(0, 0.0001)
  b.16 ~ dnorm(0, 0.0001)
  b.17 ~ dnorm(0, 0.0001)
  b.18 ~ dnorm(0, 0.0001)
  b.19 ~ dnorm(0, 0.0001)
  b.20 ~ dnorm(0, 0.0001)
  b.21 ~ dnorm(0, 0.0001)
  b.22 ~ dnorm(0, 0.0001)
  b.23 ~ dnorm(0, 0.0001)
  
  for (j in 1:(Nstate)){
    for (k in 1: (Ncat-1)){
      cut0[j,k] ~ dt(0, 1, 5)
    }
    cut[j,] <- sort(cut0[j,])
  }
}